package ddd.ajava.chapter4.question2;
import java.lang.reflect.Field;

public class PersonDisplay implements PersonAction {

	@Override
	public Person process(Person person) {

		Class<?> clazz = person.getClass();
		Field[] fields = clazz.getDeclaredFields();

		for (Field field : fields) {
			Column l = field.getAnnotation(Column.class);
			print(l.value(), field, person);
		}
		return null;
	}

	/**
	 * 打印信息
	 * @param label
	 * @param field
	 * @param person
	 */
	private void print(String label, Field field, Person person) {
		System.out.print(label + ":");
		String sysContent = "";
		if (field.getName().equals("name")) {
			sysContent = person.getName();
		} else if (field.getName().equals("sex")) {
			sysContent = person.getSex();
		} else if (field.getName().equals("age")) {
			sysContent = person.getAge() + "";
		} else if (field.getName().equals("idNo")) {
			sysContent = person.getIdNo();
		} else if (field.getName().equals("isMerried")) {
			sysContent = person.getIsMerried()+"";
		}
		System.out.println(sysContent);
	}

}
